<?php

/**
 * This is the model class for table "site_config".
 *
 * The followings are the available columns in table 'site_config':
 * @property integer $id_config
 * @property integer $general_ssl
 * @property string $general_language
 * @property integer $general_autorefreshcpdata
 * @property integer $log_login
 * @property integer $log_action
 * @property integer $log_purgetime
 * @property integer $security_max_failed_login
 * @property integer $security_captcha
 * @property integer $security_pwd_rotation
 * @property integer $email_type
 * @property string $email_from_address
 * @property string $email_from_name
 * @property string $smtp_host
 * @property string $smtp_port
 * @property string $smtp_username
 * @property string $smtp_password
 */
class SiteConfig extends CActiveRecord
{
	const SSL_HTTP = 0;
	const SSL_HTTPS = 1;
	
	const LANGUAGE_EN = 'en';
	const LANGUAGE_ESP = 'espanol';
	const LANGUAGE_LE = 'lefrancais';
	const LANGUAGE_DEU = 'deutsch';
	
	const AUTOREFRESHCPDATA_DISABLED = 0;
	const AUTOREFRESHCPDATA_HOURLY = 1;
	const AUTOREFRESHCPDATA_DAILY = 2;
	const AUTOREFRESHCPDATA_WEEKLY = 3;
	
	const ENABLE = 1;
	const DISABLE = 0;
	
	const PURGE_LOG_1DAY = 1;
	const PURGE_LOG_7DAY = 2;
	const PURGE_LOG_14DAY = 3;
	const PURGE_LOG_30DAY = 4;
	const PURGE_LOG_60DAY = 5;
	
	const MAIL_ORI = 0;
	const MAIL_SMTP = 1;
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return SiteConfig the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'site_config';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('general_ssl, general_language, general_autorefreshcpdata, log_login, log_action, log_purgetime, security_max_failed_login, security_captcha, security_pwd_rotation, email_type, email_from_address, email_from_name', 'required'),
		
			array('general_ssl, general_autorefreshcpdata, log_login, log_action, log_purgetime, security_max_failed_login, security_captcha, security_pwd_rotation, email_type', 'numerical', 'integerOnly'=>true),
			array('general_language', 'length', 'max'=>50),
			array('email_from_address, smtp_host, smtp_port, smtp_username, smtp_password', 'length', 'max'=>300),
			array('email_from_name', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_config, general_ssl, general_language, general_autorefreshcpdata, log_login, log_action, log_purgetime, security_max_failed_login, security_captcha, security_pwd_rotation, email_type, email_from_address, email_from_name, smtp_host, smtp_port, smtp_username, smtp_password', 'safe', 'on'=>'search'),
			
			array('smtp_host, smtp_port, smtp_username, smtp_password', 'required', 'on' => 'is_smtp')
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_config' => 'Id Config',
			'general_ssl' => 'SSL Options',
			'general_language' => 'Language',
			'general_autorefreshcpdata' => 'Auto-Pull Fresh cPanel Data',
			'log_login' => 'Login Activity',
			'log_action' => 'Action Log',
			'log_purgetime' => 'Purge Logs',
			'security_max_failed_login' => 'Max Failed Login Attempts',
			'security_captcha' => 'Login Captcha',
			'security_pwd_rotation' => 'Password Rotation',
			'email_type' => 'Mail Type',
			'email_from_address' => 'System Email From Address',
			'email_from_name' => 'System Email From Name',
			'smtp_host' => 'SMTP Host',
			'smtp_port' => 'SMTP Port',
			'smtp_username' => 'SMTP Username',
			'smtp_password' => 'SMTP Password'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_config',$this->id_config);
		$criteria->compare('general_ssl',$this->general_ssl);
		$criteria->compare('general_language',$this->general_language,true);
		$criteria->compare('general_autorefreshcpdata',$this->general_autorefreshcpdata);
		$criteria->compare('log_login',$this->log_login);
		$criteria->compare('log_action',$this->log_action);
		$criteria->compare('log_purgetime',$this->log_purgetime);
		$criteria->compare('security_max_failed_login',$this->security_max_failed_login);
		$criteria->compare('security_captcha',$this->security_captcha);
		$criteria->compare('security_pwd_rotation',$this->security_pwd_rotation);
		$criteria->compare('email_type',$this->email_type);
		$criteria->compare('email_from_address',$this->email_from_address,true);
		$criteria->compare('email_from_name',$this->email_from_name,true);
		$criteria->compare('smtp_host',$this->smtp_host,true);
		$criteria->compare('smtp_port',$this->smtp_port,true);
		$criteria->compare('smtp_username',$this->smtp_username,true);
		$criteria->compare('smtp_password',$this->smtp_password,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function __get($key)
	{
		$action = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
		if(method_exists($this, $action)){
			return $this->$action();
		}
		
		return parent::__get($key);
	}
	
	public function getIdConfigValue()
	{
		return empty($this->id_config)? null : $this->id_config;
	}
	
	const DEFAULT_GENERAL_SSL = self::SSL_HTTP;
	public function getGeneralSslValue()
	{
		return empty($this->id_config)? self::DEFAULT_GENERAL_SSL : $this->general_ssl;
	}
	
	const DEFAULT_GENERAL_LANGUAGE = self::LANGUAGE_EN;
	public function getGeneralLanguageValue()
	{
		return empty($this->id_config)? self::DEFAULT_GENERAL_LANGUAGE : $this->general_language;
	}
	
	const DEFAULT_GENERAL_AUTOREFRESHCPDATA = self::AUTOREFRESHCPDATA_HOURLY;
	public function getGeneralAutorefreshcpdataValue()
	{
		return empty($this->id_config)? self::DEFAULT_GENERAL_AUTOREFRESHCPDATA : $this->general_autorefreshcpdata;
	}
	
	const DEFAULT_LOG_LOGIN = self::ENABLE;
	public function getLogLoginValue()
	{
		return empty($this->id_config)? self::DEFAULT_LOG_LOGIN : $this->log_login;
	}
	
	const DEFAULT_LOG_ACTION = self::ENABLE;
	public function getLogActionValue()
	{
		return empty($this->id_config)? self::DEFAULT_LOG_ACTION : $this->log_action;
	}
	
	const DEFAULT_LOG_PURGETIME = self::PURGE_LOG_7DAY;
	public function getLogPurgetimeValue()
	{
		return empty($this->id_config)? self::DEFAULT_LOG_PURGETIME : $this->log_purgetime;
	}
	
	const DEFAULT_SECURITY_MAX_FAILED_LOGIN = 4;
	public function getSecurityMaxFailedLoginValue()
	{
		return empty($this->id_config)? self::DEFAULT_SECURITY_MAX_FAILED_LOGIN : $this->security_max_failed_login;
	}
	
	const DEFAULT_SECURITY_CAPTCHA = self::DISABLE;
	public function getSecurityCaptchaValue()
	{
		return empty($this->id_config)? self::DEFAULT_SECURITY_CAPTCHA : $this->security_captcha;
	}
	
	const DEFAULT_SECURITY_PWD_ROTATION = self::DISABLE;
	public function getSecurityPwdRotationValue()
	{
		return empty($this->id_config)? self::DEFAULT_SECURITY_PWD_ROTATION : $this->security_pwd_rotation;
	}
	
	const DEFAULT_EMAIL_TYPE= self::MAIL_SMTP;
	public function getEmailTypeValue()
	{
		return empty($this->id_config)? self::DEFAULT_EMAIL_TYPE : $this->email_type;
	}
	
	const DEFAULT_EMAIL_FROM_ADDRESS = '';
	public function getEmailFromAddressValue()
	{
		return empty($this->id_config)? self::DEFAULT_EMAIL_FROM_ADDRESS : $this->email_from_address;
	}
	
	const DEFAULT_EMAIL_FROM_NAME = '';
	public function getEmailFromNameValue()
	{
		return empty($this->id_config)? self::DEFAULT_EMAIL_FROM_NAME : $this->email_from_name;
	}
	
	const DEFAULT_SMTP_HOST = 'smtp.googlemail.com';
	public function getSmtpHostValue()
	{
		return empty($this->id_config)? self::DEFAULT_SMTP_HOST : $this->smtp_host;
	}
	
	const DEFAULT_SMTP_PORT = 465;
	public function getSmtpPortValue()
	{
		return empty($this->id_config)? self::DEFAULT_SMTP_PORT : $this->smtp_port;
	}
	
	const DEFAULT_SMTP_USERNAME = '';
	public function getSmtpUsernameValue()
	{
		return empty($this->id_config)? self::DEFAULT_SMTP_USERNAME : $this->smtp_username;
	}
	
	const DEFAULT_SMTP_PASSWORD = '';
	public function getSmtpPasswordValue()
	{
		return empty($this->id_config)? self::DEFAULT_SMTP_PASSWORD : $this->smtp_password;
	}
	
}